package entities;

import backbone.IPaintable;
import backbone.IUpdatable;
import java.awt.Graphics2D;
import main.Simulation;

/**
 * LineObject is parent class for all entities that are defined by a line.
 * @author Paul Dannenberg
 * @author Lance Co Ting Keh
 *
 */
public abstract class LineObject implements IUpdatable, IPaintable {

    private PointObject myStart;
    private PointObject myEnd;
    private double myLength;

    /**
     * @param pointObject -the first of two masses
     * @param pointObject2 -the second mass
     * @param length -length of line object
     */
    public LineObject (PointObject pointObject, PointObject pointObject2,
            double length) {
        myStart = pointObject;
        myEnd = pointObject2;
        myLength = length;
    }

    /**
     * @return returns start point mass
     */
    public PointObject getStart() {
        return myStart;
    }

    /**
     * @return returns end point mass
     */
    public PointObject getEnd() {
        return myEnd;
    }
    
    
    /**
     * @return length of the spring
     */
    public double getLength() {
        return myLength;
    }

    /**
     * @param length sets length of spring
     */
    public void setLength(double length) {
        myLength = length;
    }

    
    /**
     * @param pen returns Graphics2D pen
     */
    public void paint (Graphics2D pen) {
        int xStart = (int) myStart.getCenter().getX();
        int yStart = (int) myStart.getCenter().getY();
        int xEnd = (int) myEnd.getCenter().getX();
        int yEnd = (int) myEnd.getCenter().getY();
 
        chooseStyle(pen, xStart, yStart, xEnd, yEnd);
        pen.drawLine(xStart, yStart, xEnd, yEnd);
    }
    
    /**
     * @param pen Graphics2D pen
     * @param xStart starting x point
     * @param yStart starting y point
     * @param xEnd   end x point
     * @param yEnd   end y point
     */
    public abstract void chooseStyle(Graphics2D pen, int xStart,
            int yStart, int xEnd, int yEnd);
    /**
     * @param canvas Simulation
     * @param dt small change in time
     */
    public abstract void update (Simulation canvas, double dt);
    
}
